package com.rms.hkpc.model;


import com.rms.hkpc.callback.Callback;
import com.rms.hkpc.callback.CallbackWithProgress;
import com.rms.hkpc.model.listener.OnResultListener;
import com.rms.hkpc.model.listener.OnResultProgressListener;
import com.rms.hkpc.util.OKHttpUtil;

import java.io.File;
import java.lang.reflect.Type;

public class UtilModel {
    public void upload(String path, final OnResultListener listener, Type typeofT) {
        OKHttpUtil.getInstance().uploadFileAsync(OKHttpUtil.NET_URL + "/api/utils/uploadfile", path, new Callback() {
            @Override
            public void onSuccess(Object obj) {
                listener.onSuccess(obj);
            }

            @Override
            public void onFailed(Exception e) {
                listener.onFails(e);
            }
        }, typeofT);
    }

    public void download(String fileName, File file, String type, final OnResultProgressListener listener) {
        OKHttpUtil.getInstance().downloadFile(OKHttpUtil.NET_URL + "/api/utils/" + type + "/" + fileName, file,
                new CallbackWithProgress() {
                    @Override
                    public void onSuccess(Object obj) {
                        listener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        listener.onFails(e);
                    }

                    @Override
                    public void onProgress(int progress) {
                        listener.onProgress(progress);
                    }
                });
    }
}
